package com.xcl.controller;

import com.xcl.pojo.Information;
import com.xcl.service.FinancingServiceInter;
import com.zzg.entity.Costbreakdown;
import com.zzg.entity.FreightinformationTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName FinancingController
 * @Description 到付核销的控制器
 * @Author: xiaochaolei
 * @date 2021/7/22 15:35
 * @Version 1. 0
 */
@Controller
public class FinancingController {
    @Autowired
    FinancingServiceInter financingServiceInter;


    /**
     * 分页查询数据以及多条件查询数据
     * @param page 页码数
     * @param limit 条目数
     * @param waybill_id 运单号
     * @param city 出发地
     * @param sub_id 到达分站
     * @param arrivalCity 到达城市
     * @param eeforwardingUnit 收货单位
     * @param forwardingUnit 发货单位
     * @param date 日期
     * @param paymentMethod 付款方式
     * @param state 运单状态
     * @param verification 是否核销
     * @return map类型的数据集合
     */
    @GetMapping(value = "/FinancingControllerGetAllFinancing", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> getAllFinancing(int page,int limit,String waybill_id,String city,String sub_id,String arrivalCity
            ,String  eeforwardingUnit,String forwardingUnit,String date,String paymentMethod,String state,String verification){
        Map<String,Object> map=new HashMap<>();
        map.put("code","0");
        map.put("msg","0");
        map.put("count",financingServiceInter.getAllFinancing().size());
        map.put("data",financingServiceInter.getAllFinancingByLimit(page,limit,waybill_id,city,sub_id,
                arrivalCity,eeforwardingUnit,forwardingUnit,date,paymentMethod,state,verification));
            return map;
    }

    /**
     * 根据运单号查询货运信息
     * @param waybill_id 运单号
     * @return 货运信息
     */
    @PostMapping(value = "/FinancingControllerGetFreightinformationTableByWaybill_id", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Information getFreightinformationTableByWaybill_id(String waybill_id){
      return   financingServiceInter.getFreightinformationTableByWaybill_id(waybill_id);
    }

    /**
     * 修改是否核销状态
     * @param waybill_id 运单号
     * @return 是否成功
     */
    @PostMapping(value = "/FinancingControllerUpdateVerification", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String updateVerification(String waybill_id, Costbreakdown costbreakdown){
        if (financingServiceInter.updateVerification(waybill_id,costbreakdown)>0){
            return "成功";
        }
        return "失败";
    }
}
